package com.ysynzehao.service.impl;

import com.ysynzehao.mapper.order.OrderMapper;
import com.ysynzehao.model.order.Order;
import com.ysynzehao.service.OrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * niuzehao
 * 2018/11/30 18:06.
 */
@Service
public class OrderServiceImpl implements OrderService {

    @Autowired
    private OrderMapper orderMapper;

    @Override
    public List<Order> getAllOrder() {
        return orderMapper.selectAll();
    }

    @Override
    @Transactional(value = "orderTransactionManager", rollbackFor = Throwable.class)
    public int saveOrder(Order order) {
        int i = orderMapper.insertSelective(order);
        return i;
    }

    /**
     * @param orderId
     * @return
     */
    @Override
    public Order getOrder(int orderId) {
        return orderMapper.selectByPrimaryKey(orderId);
    }

    @Override
    public int updateOrder(Order order) {
        return orderMapper.updateByPrimaryKeySelective(order);
    }

    @Override
    public int deleteOrder(int orderId) {
        return orderMapper.deleteByPrimaryKey(orderId);
    }
}
